<template>
	<view class="ys">
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" v-if="list.length!=0"
				@click="toPage('./member?id='+item.id)">
				<view class="left">
					<view class="li">
						店铺名称：{{item.shop_name}}
					</view>
					<view class="li">
						联系方式：{{item.shop_phone}}
					</view>
					<view class="li">
						详细地址：{{item.shop_address}}
					</view>
					<view class="li">
						店铺邀请码：{{item.code}}
					</view>
				</view>
				<view class="right" @click.stop="seeCode(item)">
					<text style="color: #0095ff;">店铺会员</text>
					<image src="/static/icon/code.png" mode="widthFix"></image>
					查看二维码
				</view>
			</view>
			<view class="no-list" v-else>
				- 暂无数据 -
			</view>
			<view class="codebox" v-if="link != ''" @click="link=''">
				<view class="code" @click.stop>
					<!-- <uqrcode ref="uqrcode" canvas-id="qrcode" :value="link" @longtap="save">
					</uqrcode>
					<button @click="saveImg()">保存图片</button> -->
					<image :src="codeimg  | getImg" mode="widthFix"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		MyShop,
		ShopQrcode,
		UserQrcode
	} from "@/api/user.js"
	export default {
		data() {
			return {
				last_page: 1,
				page: 1,
				list: [],
				link: '',
				info: [],
				codeimg: ''
			}
		},
		onReady() {
			if (this.$refs.uqrcode) {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {}
				});
			}
		},
		onLoad() {
			this.MyShop()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.MyShop()
			}
		},
		methods: {
			saveImg() {
				var that = this
				that.$refs.uqrcode.save({
					success: res => {}
				});

			},
			seeCode(item) {
				this.link = `/pages/register/index?type=2&code=${item.code}&recommend_code=${this.info.recommend_code}`
				ShopQrcode({
					shop_id: item.id
				}).then(res => {
					if (res.status == 1) {
						this.codeimg = res.data
					}
				})
			},
			MyShop() {
				MyShop({
					page: this.page
				}).then(res => {
					if (res.status == 1) {
						this.list = this.list.concat(res.data.shops.data)
						this.last_page = res.data.shops.last_page
						this.info = res.data.info
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.codebox {
		background: #00000080;
		width: 100vw;
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		top: 0;
		left: 0;

		.code {
			background: #fff;
			border-radius: 8px;
			padding: 20px;
		}

		image {
			width: 80vw;
		}

		button {
			font-size: 14px;
			margin-top: 20px;
			background: #FF3C29;
			color: #fff;
		}
	}

	.list {
		padding: 10px;

		.item {
			background: #fff;
			border-radius: 5px;
			padding: 10px;
			margin-bottom: 10px;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.li {
				font-size: 14px;
				margin: 5px 0;
			}

			.right {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				font-size: 12px;
				color: #777;

				image {
					width: 60px;
				}
			}
		}
	}
</style>